package system;

import Main.*;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;

/**
 * Read settings from settings.ini
 * @author zem
 */
public class ReadSettings {

  public ReadSettings() {
        BufferedReader in;
        try {
//////open file for read
            FileInputStream fis = new FileInputStream("settings.ini");
            BufferedReader myInput = new BufferedReader(new InputStreamReader(fis));
            String thisLine = "";

//loop until EOF
//reading lines to an array
            
            while ((thisLine = myInput.readLine()) != null) {
                if (thisLine.length() > 2) {
                    char[] tmp = thisLine.toCharArray();
                    if (tmp[0] != '#') { //if line is not comment
                        int i = 0;
                        String des = ""; //desctription
                        while (tmp[i] != '=') { //while not end of description
                            des += tmp[i];
                            i++;
                        }
                        i++;
                        i++;//skipping char: "
                        String value = "";
                        while (tmp[i] != '"') {
                            value += tmp[i];
                            i++;
                        }


                        
                        if (des.equals("main_log")) {
                             value=(new PathName(value,0)).name; //make path for current OS.
                            Parameters.MainLogPath = value;

                        }
                        if (des.equals("delete_task_when_done")) {
                            Parameters.DeleteTaskWhenDone = Integer.parseInt(value); //delete tasks when done
                        }
                        if (des.equals("delete_log_file_of_task_when_done")) {
                           Parameters.DeleteLogFileOfTask = Integer.parseInt(value);
                        }
                        if (des.equals("task_folder")) {
                             value=(new PathName(value,1)).name; //make path for current OS.
                            Parameters.TaskFolder = value; //folder with tasks
                        }
                         if (des.equals("task_filename_extension")) {
                            Parameters.FileTaskExtension = value; //extension of task files
                        }
                         if (des.equals("task_priority")) {
                            Parameters.DefaultTaskPriority = Integer.parseInt(value); //default task priority
                        }
                         if (des.equals("move_done_task")) {
                            Parameters.MoveDoneTask = Integer.parseInt(value); //move done tasks
                        }
                         if (des.equals("move_done_task_to")) {
                            value=(new PathName(value,1)).name; //make path for current OS.
                           Parameters.MoveDoneTaskTo = value; //move done tasks to folder
                        }
                        if (des.equals("old_task_priority")) {
                              Parameters.OldTaskPriorirty = Integer.parseInt(value); //depending of this parameter tasks with expired run time will be done by time or priority
                        }
                         if (des.equals("max_tasks")) {
                              Parameters.MaxTaskNumber = Integer.parseInt(value); //number of maximum tasks that can be done
                        }
                         if (des.equals("language")) {
                              Parameters.Language = value; //default system language
                        }
                         if (des.equals("quit_time")) {
                              Parameters.QuitTime = Integer.parseInt(value); //time in seconds to quit after ending all tasks
                        }
                       if (des.equals("find_task_pause")) {
                              Parameters.FindTaskPause = Integer.parseInt(value); //pause in seconds between finding tasks after no task left
                        }
                        if (des.equals("move_done_task_extension")) {
                              Parameters.MoveDoneTaskExtension = value; //done task extension
                        }
                    }
                }
            }
        } catch (Exception error) { System.err.println(error);}
        }
    
}
